// DigitalUnit.h: interface for the DigitalUnit class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DIGITALUNIT_H__7F4010C7_CA57_49F5_AD98_298AC67B339B__INCLUDED_)
#define AFX_DIGITALUNIT_H__7F4010C7_CA57_49F5_AD98_298AC67B339B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "BaseMonitoringUnit.h"

struct ReportItemDigital;
class MonitoringUnitStates;

class DigitalUnit : public BaseMonitoringUnit
{
public:
	DigitalUnit(MonitoringUnitManager * pMgr);
	virtual ~DigitalUnit();

	// Overidables
	virtual void ConvertFromXML(Markup& xml);
	virtual void ConvertToXML(Markup& xml) const;
	virtual void ConvertDefFromStruct(MonUnitDef * pMonUnitDef);
	virtual void ConvertDefToStruct(MonUnitDef * pMonUnitDef) const;

	virtual void ConvertDefFromStruct(MonUnitDefEx * pMonUnitDef);
	virtual void ConvertDefToStruct(MonUnitDefEx * pMonUnitDef) const;

	virtual void GetDataString(CString& strData) const {GetDataString(strData, m_State);}
	virtual void GetInfoString(int nInfoFlag, CString& strInfo) const;
	virtual void GetRealtimeRecordString(const RealtimeRecord& record, CString& strTime, CString& strData) const;
	virtual void SetValue(float fValue) {}
	virtual float GetValue() const {return 0;}
	void MakeRecord(Record * pRecord, CTime * pTime) const;

	virtual void GenerateRandomDefinition();
	virtual void GenerateRandomData(const CTime& time);
	virtual bool CanBeShownAsHistogram() const {return false;}
	virtual void DrawHistogram(CDC& dc, const CRect& rect, COLORREF crBk, COLORREF crHisto, CFont * pFont) const;
	virtual int GetStateColorIndex() const;
	virtual void DrawRTCurveDataAxis(CDC& dc, const CRect& rect) const;
	virtual void DrawRTCurve(CDC& dc, const CRect& rect, RealtimeRecordManager * pRealtimeRecordMgr, const CTime& timeBegin, const CTime& timeEnd) const;
	virtual void DrawHSCurve(CDC& dc, const CRect& rect, RecordAckStruct * pRecordAckStruct, CurveParamStruct * pCurveParamStruct) const;

	static void DrawHSCurveDataAxis(CDC& dc, const CRect& rect, MonUnitDef * pMonUnitDef, CurveParamStruct * pCurveParamStruct);
	static void DrawHSCurveDataLine(CDC& dc, const CRect& rect, MonUnitDef * pMonUnitDef, CurveParamStruct * pCurveParamStruct);
	static void DrawHSCurveStatInfo(CDC& dc, const ReportItem& ri, DWORD dwHSCurveStatInfoMask, int x, int nRowHeight, int& nCurRow, int * pnTabStopPos);

	static void BuildReportItem(RecordAckStruct * pRecordAckStruct, ReportItem * pReportItem);
	static void BuildReportItem(RecordAckStructEx * pRecordAckStruct, ReportItemEx * pReportItem);

	// Implementations
	void SetbTriState(bool bTriState) {m_bTriState = bTriState;}
	bool GetbTriState() const {return m_bTriState;}

	void SetStateName(MonitoringUnitState::States State, const CString& strStateName);
	const CString& GetStateName(MonitoringUnitState::States State) const;

protected:
	virtual void GetStateString(CString& strState, MonitoringUnitState::States State) const;
	virtual void GetDataString(CString& strData, MonitoringUnitState::States State, float fValue = 0) const {GetStateString(strData, State);}

	static void AccumulateReportItem(ReportItemDigital * pDigitalItem, const RecordItem& record, const CTimeSpan& timespan, MonitoringUnitState::States& PrevState);

protected:
	bool m_bTriState;
	CString m_strStateName[3];
};

#endif // !defined(AFX_DIGITALUNIT_H__7F4010C7_CA57_49F5_AD98_298AC67B339B__INCLUDED_)
